import 'package:flutter_changdian_football/api/api_response.dart';
import 'package:flutter_changdian_football/api/req/match/req_match.dart';
import 'package:flutter_changdian_football/config/enum/load_state.dart';
import 'package:flutter_changdian_football/model/match/history_match_record_model.dart';
import 'package:flutter_changdian_football/widget/toast/custom_toast.dart';
import 'package:get/get.dart';

class GameRecordDescController extends GetxController {

  GameRecordDescController({
    required this.clubId,
    required this.matchId
  });

  final String clubId;
  final String matchId; 

  @override
  void onInit() {
    super.onInit();

    initData();
  }

  LoadState state = LoadState.loading;

  HistoryMatchRecordModel? historyMatchRecordModel;

  initData() async {
    var resp = await ReqMatch.historyMatchRecord(clubId: clubId, matchId: matchId);
    if (resp.status == Status.completed) {
      if (resp.data['code'] == '200') {
        historyMatchRecordModel = HistoryMatchRecordModel.fromJson(resp.data['data']);

        if (resp.data['data'] != null) {
          state = LoadState.success;
        } else {
          state = LoadState.empty;
        }

        update();
      } else {
        CustomToast.showTextToast('${resp.data['msg']}');
        state = LoadState.error;
        update();
      }
    } else {
      state = LoadState.network;
      update();
    }
  }

}